import Vue from '@/main.js';

//获取上级机构列表
export function getShangJiJiGouList(code) {
  var path = `/business/company/getFatherCompanies?shortName=`;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}
//子级地区信息
export function getcityList(code) {
  var path = `/business/dictionary/queryAreaList?fatherCode=${code}`;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}
export function getCompanySubList(params) { //子级机构列表
  var path = `/business/company/subList`;
  return Vue.$http.post(path, params)
    .then((res) => {
      return res.data.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}

export function getAgencyList(params) {
  var path = "/business/company/list";
  return Vue.$http.post(path,params)
    .then((res) => {
      return res.data.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}



export function getFatherAgencies(name) {
  var path = "/business/agency/getFatherAgencies?name=" + name;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}


export function insertAgency(insertForm) {
  var path = "/business/company/insert";
  return Vue.$http.post(path, insertForm)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}




export function deleteinstInformation(id) {
  var path = "/business/company/delete?id=" + id;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}



export function getInDetail(id) {
  var path = "/business/company/detail?id=" + id;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}


export function updateinstInfo(insertForm) {
  var path = "/business/company/update";
  return Vue.$http.post(path, {
    "id": insertForm.id,
    "shortName": insertForm.shortName,
    "superAdministratorId": insertForm.superAdministratorId,
    "type": insertForm.type,
    "fatherCompanyId": insertForm.fatherCompanyId,
    "criCode": insertForm.criCode,
    "contactName": insertForm.contactName,
    "telephoneNumber": insertForm.telephoneNumber,
    responsiblePersonName: insertForm.responsiblePersonName,
    address:insertForm.address,
  })
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}


export function getDictionaryList(category) {
  var path = "/business/dictionary/queryList?category=" + category;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}



export function bindingAU(agencyId, userId) {
  var path = "/business/company/bindingCU?companyId=" + agencyId + "&userId=" + userId;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}

export function unbindingAU(agencyId, userId) {
  var path = "/business/company/unbindingCU?companyId=" + agencyId + "&userId=" + userId;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}
export function getUserList(params) {
  var path = "/auth/user/getUserList";
  return Vue.$http.post(path, params)
    .then((res) => {
      return res.data.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}
export function mygetUserListForBindingCU(params) { //超级管理员列表 旧版
  var path = "/business/company/getUserListForBindingCU";
  return Vue.$http.post(path, params)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}
export function myGetSuperDetail(userId) { //新版超级管理员 
  var path = `/business/company/getSuperAdministratorInfo?userId=${userId}`;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}
export function getDepartmentHierarchically(params) {
  var path = "/auth/department/getDepartmentListByUnit";
  return Vue.$http.post(path, params).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}



export function getPostListByDepId(depId) {
  var path = "/business/companyPost/getPostListByDepId";
  return Vue.$http.post(path, {
    depId: depId,
  }).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}

export function getUserMainStaff(id) { //得到员工主业id(不为0则是有主业)
  var path = "/business/companyStaff/getUserMainStaff?userId=" + id;
  return Vue.$http.get(path).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}

export function addStaff(params) {
  var path = "/business/companyStaff/addStaff";
  return Vue.$http.post(path, params).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}



export function getAddedUserList(params) {
  var path = "/business/companyStaff/addedStaffListByCompanyId";
  return Vue.$http.post(path, params).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}
export function mydeleteUserPost(params) { //删除员工岗位
  var path = "/business/companyStaff/deleteUserPost";
  return Vue.$http.post(path, params).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}
export function mygetaddUserPost(params) { //给员工添加岗位
  var path = "/business/companyStaff/addUserPost";
  return Vue.$http.post(path, params).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}
export function myupdateUserPost(params) { //修改员工岗位
  var path = "/business/companyStaff/updateStaff";
  return Vue.$http.post(path, params).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}
export function deleteStaff(staffId, userId) {
  var path = `/business/companyStaff/delete?staffId=${staffId}&userId=${userId}`;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}

export function getBreadcrumbs(agencyId) {
  var path = "/business/company/getFatherCompanyData?companyId=" + agencyId;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}

export function getAgencyStaffDetail(id) {
  var path = `/business/companyStaff/detail?id=${id}`;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}



export function updateStaff(id, agencyId, userId, depIds, postIds) {
  var path = "/business/agencyStaff/updateStaff";
  return Vue.$http.post(path, {
    id: id,
    agencyId: agencyId,
    userId: userId,
    depIds: depIds,
    postIds: postIds,
  }).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}

